package com.xu.security.model;

import lombok.Getter;
import lombok.Setter;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.Collections;
import java.util.List;

/**
 * 登录用户信息
 *
 * @Author: 许乾伟
 * @Date: 2024/2/27 14:27
 */
public class OnlineUser implements UserDetails {
    /**
     * 主体用户
     */
    @Setter
    private String principal;
    /**
     * 安全凭证
     */
    @Setter
    private String credentials;
    /**
     * token
     */
    @Getter
    @Setter
    private String token;
    /**
     * token发放时间
     */
    @Getter
    @Setter
    private Long loginTime;
    /**
     * token刷新时间
     */
    @Getter
    @Setter
    private Long refreshTime;
    /**
     * token过期时间
     */
    @Getter
    @Setter
    private Long expireTime;

    /**
     * 用户信息
     */
    @Getter
    @Setter
    private CurrentUser user;
    /**
     * 接口权限
     */
    @Getter
    @Setter
    private List<String> permissions;
    /**
     * 角色信息
     */
    @Getter
    @Setter
    private List<? extends CurrentRole> roles;
    /**
     * 菜单信息
     */
    @Getter
    @Setter
    private List<? extends CurrentMenu> menus;

    /**
     * 权限
     * @return
     */
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return Collections.emptyList();
    }

    @Override
    public String getPassword() {
        return credentials;
    }

    @Override
    public String getUsername() {
        return principal;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
}
